<%@ page language="java" contentType="text/html;charset=utf-8"%>
<%@ page import="com.kbwsoft.esiframe.core.util.*" %>
<%@ page import="com.kbwsoft.esiframe.usermanage.*"%>
<%@ page import="com.kbwsoft.app.order.*"%>
<%@ page import="com.kbwsoft.util.*"%>
<%@ page import="sun.jdbc.rowset.*"%>
<%@ page import="com.alibaba.fastjson.*"%>


<%
  String count = request.getParameter("count");
  int start = Integer.parseInt(request.getParameter("start"));
  int end = start + Integer.parseInt(count);
  String ntp = request.getParameter("ntp");
  String callback = request.getParameter("callback");
  String text = java.net.URLDecoder.decode(request.getParameter("text") , "UTF-8");
  
  DBTransUtil transUtil = new DBTransUtil();
  String strSql = "select * from v_news_list where flag = '0' and status <> '0' and newstype = '"+ntp+"' ";
  if(!text.equals("") && text != null){
    strSql = strSql + " and (title like binary '%"+text+"%' or zy like binary '%"+text+"%')";
  }
  strSql = strSql + " and audittime is not null order by status asc, audittime desc";
  CachedRowSet crs2 = transUtil.getResultBySelect(strSql);
  //int size = transUtil.getSqlCount(strSql);
  strSql = strSql + " limit " + start + "," + end;
  CachedRowSet crs1 = transUtil.getResultBySelect(strSql);
  System.out.println(strSql);
  
  String newspic = "";  //�������
  String title= "";
  String zy= "";
  String newid= "";
  String time_dd= "";
  String author= "";
  String ylwx= "";

  StringBuffer str = new StringBuffer("{\"events\":[");
  int i= 0;
  while(crs1.next()){
  	if(i!=0){
	 str.append(",");
	}
	i++;
	newid = Tools.nvl(crs1.getString("newid"));
	author = Tools.nvl(crs1.getString("author"));
	ylwx = Tools.nvl(crs1.getString("ylwx"));
	title = Tools.nvl(crs1.getString("title"));
	newspic = Tools.nvl(crs1.getString("newspic")); 
	zy = Tools.nvl(crs1.getString("zy"));
	time_dd = Tools.nvl(crs1.getString("time_dd"));
    str.append("{\"newid\":\"");                        
    str.append(newid).append("\","); 
    str.append("\"author\":\"");
    str.append(author).append("\",");
    str.append("\"ylwx\":\"");
    str.append(ylwx).append("\",");
    str.append("\"title\":\"");
    str.append(title).append("\",");
    str.append("\"newspic\":\"");
    str.append(newspic).append("\",");
    str.append("\"zy\":\"");
    str.append(zy).append("\",");
    str.append("\"time_dd\":\"");
    str.append(time_dd);
    str.append("\"}");
  }
  str.append("],\"total\":"+(crs2.size())+"}");
  response.setCharacterEncoding("utf-8");
  response.getWriter().print(callback + "(" +str.toString()+ ")");
%>

<%
  //response.getWriter().print(str.toString());
  //JSONObject json = new JSONObject();
  //response.getWriter().write(JSON.parseObject(json));
  //response.setContentType("application/javascript; charset=utf-8");
  //response.getWriter().print(JSON.parseObject(str.toString()));
%>
